package io.jt808.proto.cmd;

import io.norland.buffer.AutoBuffer;
import io.norland.annotations.Proto;
import io.norland.proto.IProto;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 删除多边形区域
 */
@Proto("8605")
@Data
public class JT8605 implements IProto {
    /**
     * 区域数,本条消息中包含的区域数，不超过125个，多于125个建议用多条消息，0为删除所有圆形区域
     */
    private short areasCount;
    /**
     * 要删除ID列表
     */
    private List<Integer> areaIDs;

    public byte[] writeToBytes() {
        AutoBuffer bytes = new AutoBuffer();
        bytes.writeByte(areasCount);
        for (int areaId : areaIDs) {
            bytes.writeInt(areaId);
        }
        return bytes.array();
    }

    public void readFromBuf(AutoBuffer buffer) {
        areasCount = buffer.readByte();
        areaIDs = new ArrayList<>();
        while (buffer.isReadable()) {
            areaIDs.add(buffer.readInt());
        }
    }

//    public static void main(String[] args) {
//        byte[] bytes = new byte[]{
//                0x03,
//                0x00, 0x00, 0x00, 0x01,
//                0x00, 0x00, 0x00, 0x02,
//                0x00, 0x00, 0x00, 0x03
//        };
//        JT8601 jt8601 = new JT8601();
//        jt8601.readFromBuf(new AutoBuffer(bytes));
//        System.out.println(new String(bytes).equals(new String(jt8601.writeToBytes())));
//    }
}